package com.jaspec;

import static junit.framework.Assert.*;

public class JaspecObject<T> {

  protected final T obj;
  protected boolean not = false;

  protected JaspecObject(T obj) {
    this.obj = obj;
  }

  public JaspecObject(T obj, boolean not) {
    this(obj);
    this.not = not;
  }

  /**
   * @return The object
   */
  public T getObj() {
    return obj;
  }

  /**
   * Check that the object is equal the another.
   * 
   * @param actual The other object
   */
  public void be(Object actual) {
    if (!not) {
      assertEquals("The objects should be equal", obj, actual);
    } else {
      assertNotSame("The objects should be different", obj, actual);
    }
  }

  /**
   * Check that the object is null.
   */
  public void be_null() {
    if (!not) {
      assertNull("The object should be null", obj);
    } else {
      assertNotNull("The object should not be null", obj);
    }
  }

  /**
   * Check that the object is instance of a certain class.
   * 
   * @param clazz The class
   */
  public void be_instanceof(Class<?> clazz) {
    assertNotNull("The given class is null", clazz);
    boolean isInstanceOf = obj.getClass().equals(clazz);
    if (!not) {
      assertTrue("The object should be an instance of " + clazz.getCanonicalName(), isInstanceOf);
    } else {
      assertFalse("The object should not be an instance of " + clazz.getCanonicalName(),
          isInstanceOf);
    }
  }
}
